<template>
	<view class="content">
		<view style="display: flex; justify-content: space-between; width: 100%;padding:15rpx 20rpx;">
			<view class='left'>
				<view :class="current == 1 ? 'active' : ''" data-item='1' @tap='send'>新歌 <text>|</text></view>
				<view :class="current == 2 ? 'active' : ''" data-item='2' @tap='send'>新碟 <text>|</text></view>
				<view :class="current == 3 ? 'active' : ''" data-item='3' @tap='send'>数字专辑</view>
			</view>
			<view class="right">
				<text>更多<u-icon name="arrow-right"></u-icon></text>
			</view>
		</view>

		<view class="conten_box">
			<scroll-view class="major" scroll-x>
				<!-- 新歌 -->
				<view class="box" v-if="current == 1 ">
					<view class="scroll-item" v-for="(item,index) in songsList" :key="item.id">
						<view class="scroll-item2" v-for="child in item" :key="child.id">
							<image class='image' @tap="sends(child.id,child)" :src="child.picUrl"></image>
							<view class="main">
								<view>
									{{child.name}}
								</view>
								<text v-if="child.song.alias.length == 1">{{child.song.alias[0]}}</text>
								<text v-else>{{child.song.artists[0].name}}</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 新碟 -->
				<view class="box" v-if="current == 2 ">
					<view class="scroll-item" v-for="(item,index) in newsongs" :key="item.id">
						<view class="scroll-item2" v-for="child in item" :key="child.id">
							<image class='image' @tap="sends(child.id,child)" :src="child.picUrl"></image>
							<view class="main">
								<view>
									{{child.name}}
								</view>
								<text v-if="child.artists[0].name.length == 2">{{child.artists[0].name}}</text>
								<text v-else>{{child.artists[0].name}}</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 数字专辑 -->
				<view class="box" v-if="current == 3 ">
					<view class="scroll-item" v-for="(item,index) in newdisc" :key="item.id">
						<view class="scroll-item2" v-for="child in item" :key="child.id">
							<image class='image' @tap="sends(child.id,child)" :src="child.coverUrl"></image>
							<view class="main">
								<view>
									{{child.albumName}}
								</view>
								<text v-if="child.artistName.length == 3">{{child.artistName}}</text>
								<text v-else>{{child.artistName}}</text>
							</view>
						</view>
					</view>
				</view>

			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getBanner,
		getRecSongsSheet,
		getRceSongsList,
		getDetail,
		getNewalbum,
		getNewdisc
	} from "../../network/discover";
	import {
		detectMusic,
		playMusic,
		getLyric
	} from "../../network/play"
	export default {
		data() {
			return {
				current: 1
			}
		},
		props: ['songsList', 'newsongs', 'newdisc'],
		methods: {
			send(e) {
				if (e.currentTarget.dataset.item == 1) {
					this.current = 1
				} else if (e.currentTarget.dataset.item == 2) {
					this.current = 2
				} else if (e.currentTarget.dataset.item == 3) {
					this.current = 3
				}
			},
			sends(id, list) {
				playMusic(id, list).then(res => {
					this.$store.commit('getmusicurl', res.data[0])
					let arr = []
					const name = list.song.name
					const authorId = list.song.artists[0].id
					const author = list.song.artists[0].name
					const pic = list.picUrl
					const mvid = list.song.mvid
					const dt = this.$moment(list.song.duration).format('mm:ss')
					let newarr = arr.concat(name, author, pic, authorId, mvid, dt)
					// let newarr = arr.concat(pic,name,authorId,author)
					this.$store.commit('getmusicmsg', newarr)
					this.$store.commit('getfalg', true) //播放
					this.$store.commit('getsongId', id)
				})
			}
			// async sends(id, list) {
			// 	const {
			// 		data: res
			// 	} = await playMusic();
			// 	this.$store.commit('getmusicurl', res.data[0])
			// 	let arr = []
			// 	const name = list.song.name
			// 	const authorId = list.song.artists[0].id
			// 	const author = list.song.artists[0].name
			// 	const pic = list.picUrl
			// 	const mvid = list.song.mvid
			// 	const dt = this.$moment(list.song.duration).format('mm:ss')
			// 	let newarr = arr.concat(name, author, pic, authorId, mvid, dt)
			// 	this.$store.commit('getmusicmsg', newarr)
			// 	this.$store.commit('getfalg', true) //播放
			// 	this.$store.commit('getsongId', id)
			// }, //点击图片播放

		},
		onLaunch() {
			this.send()
		}
	}
</script>

<style>
	.content {
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box;
		box-sizing: border-box;
		display: flex;
		font-weight: 600;
		flex-direction: column;
		color: #ccc;
		border-top: 5px solid #f5f5f5;
	}

	.left {
		display: flex;
	}

	.left>view {
		display: flex;
		align-items: center;
		font-size: 16px;
	}

	.left>view>text {
		margin: 0 20rpx;
		color: #969696;
		font-size: 5px;
	}

	.right {
		display: flex;
		align-items: center;
		width: 120rpx;
		height: 100%;
		border: 1px solid #ccc;
		border-radius: 10px;
		justify-content: center;
		padding: 5rpx;
		color: black;
		font-weight: 500;
		font-size: 20rpx;
	}

	.image {
		width: 100rpx !important;
		height: 100rpx;
		border-radius: 10px;
	}

	.active {
		color: black;
	}

	.scroll-item {
		margin: 15rpx 30rpx;
		
	}

	.main {
		/* display: flex;
		justify-content: space-between;
		flex-direction: column;
		font-weight: lighter; */
		/* text-align: left; */
		color: black;
		width: 550rpx;
		text-overflow: ellipsis;
	}

	.main>view {
		margin: 10rpx 20rpx;
	}

	.main>text {
		color: #ccc;
		width: 100%;
		margin: 10rpx 20rpx;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.major {
		/* width: 95%; */
		/* border: 1px solid red; */
	}

	.box {
		display: flex;
	}

	.scroll-item2 {
		display: flex;
		margin-top: 15rpx;
		/* margin-left: 20rpx; */
		
	}

	.icon-bg {
		background-color: red;
		border-radius: 6px;
		/* opacity: 0.5; */
		position: absolute;
		top: 18px;
		right: 5px;
		color: #FFFFFF;
	}

	.icon-img {
		width: 10px;
		height: 10px;
		margin: 0 3px;
	}
</style>
